/**
 * This component renders a present input field with auto-suggest.
 */
$.Controller( "PresentInput", {
  init: function(){
    this.element.html("js/view/PresentInput.ejs", {});
    $('#present-name-input').autocomplete({
    	source: function (req, resp){
    		$.ajax({
    		  type: 'GET',
    		  url: 'present/find/name/'+req.term,
    		  contentType : 'application/json',
    		  dataType: 'json',
    		  success: function (data) {
    			resp(data);
    		  }
    		 });
    	}
    });
  },
  "#start-register-dialog click": function(el) {
	  var me = this,
	  	presentName = $('#present-name-input').val(),
	  	present = new Present(),
	  	conversation = new RegisterConversation();
	  
	  present.attr('name', presentName);
	  conversation.present = present;
	  
	  conversation.save(function (result) {
		  me.options.startDialogCallback(result);
	  });
  }
});
